package pcsd.task;

import java.io.Serializable;

import pcsd.Result;
import pcsd.Task;

/**
 * This tasks calculates one Fibonacci number.
 * 
 * @author Benjamin Ertl, Justinas Murzinas, Boyan Mihaylov
 */
public class Fib implements Task, Serializable {

	private static final long serialVersionUID = 81376L;
	
	/** The Fibonacci number to calculate */
	private final int n;
	
	public Fib(int n) {
		this.n = n;
	}

	@Override
	public Result execute() {
		long result = calculateFib(this.n);
		return new Result(0, "" + result);
	}
	
	private static long calculateFib(int n) {
		if (n == 0 || n == 1) {
			return n;
		}
		else {
			return calculateFib(n - 1) + calculateFib(n - 2);
		}
	}
}
